package cn.jiyun.controller;

import cn.jiyun.config.User;
import cn.jiyun.config.UserProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class ConfigController {

    @Value("${user.username}")
    private String username;
    @Value("${user.age}")
    private Integer age;
    @Value("${user.phone}")
    private String phone;
    /*@Value("${user.hobby}")
    private String[] hobby;*/

    /**
     * 将读取的配置信息，返回给前端
     */
    @RequestMapping("/config")
    public Map<String,Object> config(){
        Map<String,Object> map = new HashMap<>();
        map.put("username",username);
        map.put("age",age);
        map.put("phone",phone);
        //map.put("hobby",hobby);
        return map;
    }

    /*@Autowired
    private UserProperties userProperties;*/

    /**
     * 将通过属性注入类读取的配置信息返回前端
     */
    /*@RequestMapping("/config2")
    public UserProperties config2(){
        return userProperties;
    }*/

    @Autowired
    private User user;

    @RequestMapping("/config3")
    public User config3(){
        return user;
    }

}
